package com.ctgu.tengyun.util;

public class CompareUtil {
	
	public static <T extends Comparable<T>> int compare(T a, T b) {
		if (null == a && null == b){
			return 0;
		}else if (null == a && null != b) {
			return -1;
		}else if (null != a && null == b) {
			return 1;
		}else {
			return a.compareTo(b);
		}
	}
	

	public static <T extends Comparable<T>>  boolean equals(T a, T b) {
		return compare(a, b) == 0;
	}

	/**
	 * less than or equals
	 */
	public static <T extends Comparable<T>>  boolean le(T a, T b) {
		return compare(a, b) <= 0;
	}

	/**
	 * less than
	 */
	public static <T extends Comparable<T>>  boolean lt(T a, T b) {
		return compare(a, b) < 0;
	}

	/**
	 * greater than
	 */
	public static <T extends Comparable<T>>  boolean gt(T a, T b) {
		return compare(a, b) > 0;
	}

	/**
	 * greater than or equals
	 */
	public static <T extends Comparable<T>>  boolean ge(T a, T b) {
		return compare(a, b) >= 0;
	}

	
	public static <T extends Comparable<T>>  boolean notEquals(T a, T b) {
		return compare(a, b) != 0;
	}

	public static <T extends Comparable<T>>  boolean betweenIncluded(T lower, T upper, T x) {
		return ge(x, lower) && le(x, upper);
	}
	
	private static long MAX_UNACTIVE_TIMELENGTH_IN_MILLISECONDS = 45L * 24 * 60 * 60 * 1000 * 1000; // 45天之后不能再激活

}
